local turtle = require('turtle')
local vdb = require('vdb')
local tl = turtle.TurtleList.new()
tl:import("main")

---@export
---@desc 查询海龟汤关键字
---@param index integer
---@param key string
---@return string
function FindKey(index, key)
    return tl:index(index):find(key)
end

---@export
---@desc 获取海龟汤提示的蘑菇数
---@param index integer
---@return integer
function GetTurtleMushCount(index)
    return tl:index(index):get_mush_count()
end

---@export
---@desc 检查该海龟汤是否完成
---@param index integer
---@return boolean
function CheckTurtleComplete(index)
    return tl:index(index):check()
end

---@export
---@desc 解锁海龟汤当前提示
---@param index integer
function UnLockTurtleTip(index)
    tl:index(index):unlock()
end

---@export
---@desc 当前海龟汤提示是否解锁
---@param index integer
---@return boolean
function IsUnLockTurtleTip(index)
    local t = tl:index(index)
    return t.source[t.tip_index].complete
end

---@export
---@desc 获取海龟汤展示
---@param index integer
---@return string
function GetTurtleDisplay(index)
    return tl:index(index):display()
end

---@export
---@desc 获取海龟汤标题
---@param index integer
---@return string
function GetTurtleTitle(index)
    return tl:index(index).title
end

---@export
---@desc 获取海龟汤下一提示展示
---@param index integer
---@return string
function GetTurtleNextTipDisplay(index)
    return tl:index(index):next_tip()
end

---@export
---@desc 获取海龟汤上一提示展示
---@param index integer
---@return string
function GetTurtleLastTipDisplay(index)
    return tl:index(index):last_tip()
end

---@export
---@desc 重置海龟汤
---@param index integer
function ResetTurtle(index)
    tl:index(index):reset()
end

---@export
---@desc 查询相似度
---@param index integer
---@param comp string
---@return integer
function QuerySimlarity(index, comp)
    local simlarity = 0.0 ---@type integer
    local _similarity = 0.0 ---@type number
    for _, value in ipairs(tl:index(index).source) do
        _similarity = vdb.cosine_similarity(value.origin, comp)
        if _similarity > simlarity then
            simlarity = _similarity
        end
    end
    ---@diagnostic disable-next-line: cast-local-type
    simlarity = math.tointeger(math.round(simlarity * 100.0))
    ---@diagnostic disable-next-line: return-type-mismatch
    return simlarity
end
